<?php


class PokaYokeInteger extends PokaYokeRetriever
{
	public function retrieve( $options )
	{
    	// String Cast is used to avoid a bug while checking large integer values
		if ( $this->value !== "" && ctype_digit( (string) $this->value ) ) {
			// Minimum comparison
			if ( isset( $options[ 'min' ] ) && $options[ 'min' ] >= $this->value ) {
            	throw new PokaYokeException(
					"Current value [ " . $this->value . " ] "
					."is lower than minimum value [ " . $options[ 'min' ] . " ]"
				);
			}
			
			// Maximum comparison
            if ( isset( $options[ 'max' ] ) && $options[ 'max' ] <= $this->value ) {
            	throw new PokaYokeException(
					"Current value [ " . $this->value . " ] "
					. "is higher than maximum value [ " . $options[ 'max' ] . " ]"
				);
			}
			
			// Equality comparison
            if ( isset( $options[ 'equals' ] ) && $options[ 'equals' ] !== $this->value ) {
            	throw new PokaYokeException(
					"Current value [ " . $this->value . " ] "
					. "is not equal to value [ " . $options[ 'equals' ] . " ]"
				);
			}

    		return ( ( int ) $this->value );
    	}

    	throw new PokaYokeException(
			"Cannot filter the value [ type: " . gettype( $this->value ) . " ] into integer type"
		);

		return false;
	}
}


?>